define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'message/index' + location.search,
                    add_url: 'message/add',
                    edit_url: 'message/edit',
                    del_url: 'message/del',
                    multi_url: 'message/multi',
                    import_url: 'message/import',
                    table: 'message',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'title', title: __('标题')},
                        {field: 'description', title: __('描述')},
                        {field: 'type', title: __('通知类型'),searchList: {"1":__('全部'),"2":__('指定用户')},formatter: function (value, row) {
                        var text =  '全部';
                        if(value ==2){
                            text = '指定用户';
                        }
                        return text;
                        }},
                        {field: 'file_type', title: __('消息类型'),searchList: {"1":__('文字'),"2":__('图片')},formatter: function (value, row) {
                            var text =  '文字';
                            if(value ==2){
                                text = '图片';
                            }
                            return text;
                         }},
                        {field: 'image', title: __('图片'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'status', title: __('Status'),searchList: {"1":__('正常'),"0":__('隐藏')},formatter: function (value, row) {
                            var text =  '正常';
                            if(!value){
                                text = '隐藏';
                            }
                        return text;
                        }},
                        {field: 'create_time', title: __('创建时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'update_time', title: __('更新时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
